package br.usjt.component.login.assembler;

import br.usjt.component.login.dto.RecursoDTO;
import br.usjt.component.login.model.Recurso;

public class RecursoAssembler {

    private Recurso entity;
    private RecursoDTO dto;

    public RecursoAssembler(Recurso entity) {
        this.entity = entity;
        toDto(entity);
    }

    public RecursoAssembler(RecursoDTO dto) {
        this.dto = dto;
        toEntity(dto);
    }

    private void toEntity(RecursoDTO dto) {
        this.entity = new Recurso();

        this.entity.setDescricao(dto.getDescricao());
        this.entity.setId(dto.getId());
        this.entity.setNomePagina(dto.getNomePagina());
        this.entity.setStatus(dto.isAtivo());
        this.entity.setUrl(dto.getUrl());
    }

    private void toDto(Recurso entity) {
        this.dto = new RecursoDTO();

        this.dto.setDescricao(entity.getDescricao());
        this.dto.setId(entity.getId());
        this.dto.setNomePagina(entity.getNomePagina());
        this.dto.setAtivo(entity.isStatus());
        this.dto.setUrl(entity.getUrl());

    }

    public Recurso getEntity() {
        return entity;
    }

    public RecursoDTO getDto() {
        return dto;
    }

    public static void toEntityAttached(Recurso undetached, Recurso attached) {
        attached.setDescricao(undetached.getDescricao());
        attached.setStatus(undetached.isStatus());
        attached.setNomePagina(undetached.getNomePagina());
        attached.setUrl(undetached.getUrl());
    }
}
